package com.atguigu.spzx.manager.controller;

import com.atguigu.spyx.model.common.Result;
import com.atguigu.spyx.model.common.com.atguigu.spyx.model.entity.product.Product;
import com.atguigu.spyx.model.dto.system.ProductDto;
import com.atguigu.spyx.model.dto.system.ProductSaveDto;
import com.atguigu.spyx.model.vo.system.ProductVo;
import com.atguigu.spzx.manager.service.ProductService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import lombok.Data;
import org.springframework.web.bind.annotation.*;

/**
 * @author LT
 * @create 2023-11-10-19:29
 */
@RestController
@RequestMapping("/admin/product/product")
public class ProductController {

    @Resource
    ProductService productService;

    @GetMapping("/{pageNum}/{pageSize}")
    public Result page(@PathVariable("pageNum")Integer pageNum,
                       @PathVariable("pageSize")Integer pageSize,
                        ProductDto productDto){
        PageInfo<ProductVo> pageInfo = productService.page(pageNum,pageSize,productDto);
        return Result.ok().data(pageInfo);
    }

    @PostMapping("/save")
    public Result save(@RequestBody ProductSaveDto productSaveDto){
        productService.save(productSaveDto);
        return Result.ok();
    }

    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable("id") Long id){
        ProductSaveDto productSaveDto = productService.getById(id);
        return Result.ok().data(productSaveDto);
    }
    @PutMapping("/updateById")
    public Result updateById(@RequestBody ProductSaveDto productSaveDto){
        productService.updateById(productSaveDto);
        return Result.ok();
    }
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Long id){
        productService.deleteById(id);
        return Result.ok();
    }
    //商品审核
    @GetMapping("/updateAuditStatus/{id}/{auditStatus}")
    public Result updateAuditStatus(@PathVariable("id")Long id,
                                    @PathVariable("auditStatus")Integer auditStatus){
        productService.updateAuditStatus(id,auditStatus);
        return Result.ok();
    }
    //商品上下架
    @GetMapping("/updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable("id")Long id,
                               @PathVariable("status")Integer status){
        productService.updateStatus(id,status);
        return Result.ok();
    }

}
